#!/bin/bash

RM_MK=true

if [ "x$1" = "x-d" ]; then
    unset RM_MK;
    shift;
fi;

JS2SCHEME_PATH=/home/flo/programming/js/js-tools
JS2SCHEME_RUNTIME_PATH=$JS2SCHEME_PATH/js-runtime
JS2SCHEME_BUILD=$JS2SCHEME_PATH/build

mkdir -p $JS2SCHEME_BUILD/exes
mkdir -p $JS2SCHEME_BUILD/Makefiles
TMPMK=`mktemp $JS2SCHEME_PATH/build/Makefiles/Makefile.XXXXX`  || exit 1
TARGET=`mktemp $JS2SCHEME_PATH/build/exes/run.XXXXX`  || exit 1

echo "Makefile: " $TMPMK
echo "Target: " $TARGET

echo "SOURCE_DIR = " $PWD > $TMPMK
echo "SOURCES = " $* >> $TMPMK
echo "TARGET = " $TARGET >> $TMPMK
echo "JS2SCHEME_DIR = .." >> $TMPMK
echo "VPATH = " $PWD >> $TMPMK
echo "include Makefile.include" >> $TMPMK

make -f $TMPMK -C $JS2SCHEME_BUILD dirs
make -f $TMPMK -C $JS2SCHEME_BUILD

EXIT_STATUS=$?
if [ $EXIT_STATUS = 0 ]; then
  exit $EXIT_STATUS;
else
  exit 3;
fi
